<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>会员列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <link rel="stylesheet" type="text/css" href="../mobile/js/layer/css/layui.css" />
  <script src="../mobile/js/jquery-1.9.1.js"></script>
  <script src="../mobile/js/layer/layui.js"></script>
  <script src="./js/common.js"></script>
  <script type="text/javascript">
      //访问是否登录,ajax同步请求
      logins(); 
  </script>
</head>
<body>
<div style="margin: -30px 20px 20px 20px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>会员列表</legend>
</fieldset>
<blockquote class="layui-elem-quote">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="请输入会员昵称">
        </div>&nbsp;
	   <button class="layui-btn btns" id="search" data-type="reload"><i class="layui-icon" style="color: #fff">&#xe615;</i>搜索</button>
	   <button class="layui-btn" style="border: 1px solid #35C4F9;background: none;color:#35C4F9" id="daochu"><i class="layui-icon" style="color: #35C4F9">&#xe641;</i>导出会员</button>
	   <button class="layui-btn btns_del" id="delAll"><i class="layui-icon" style="color: #fff">&#xe640;</i>批量删除</button>
</blockquote>
<table class="layui-hide" id="list" lay-filter="list"></table>
</div>
<!-- <script type="text/html" id="status">
    {{# if(d.status==1){ }}
       <input type="checkbox" name="status" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" checked value="{{d.id}}">
    {{# }else{  }}
       <input type="checkbox" name="status" lay-skin="switch" lay-filter="status" lay-text="开启|关闭" value="{{d.id}}">
    {{# } }}
</script> -->
<script type="text/html" id="action">
    <a  title="编辑"><i class="layui-icon" style="color: #5FB878;font-size: 25px;">&#xe642;</i></a>
    <a lay-event="del" title="删除"><i class="layui-icon" style="color:#FF5722;font-size: 25px;">&#xe640;</i></a>
</script>
<script>
layui.use(['table','form'], function() {
      var table = layui.table,form = layui.form,$ = layui.jquery;
      var urls = url + "/admin/userlist/userlists";
      var tableIn = table.render({
          elem: '#list',
          url: urls,
          method: 'post',
          page: true,
          where: {},
          cols: [[
              {checkbox:true,fixed: true},
              {field: 'user_id', title: '编号', fixed: true,width:100,align: 'center', },
              {field: 'nickname', title: '会员昵称'},
              {field: 'openid', title: 'openid',},
              {field: 'reg_time', title: '注册时间',width:200,align: 'center', },
            /*  {title: '启用状态',width:100, align: 'center', toolbar: '#status'},*/
              {title: '操作', width: 160, align: 'center', toolbar: '#action'}
          ]],
          limit: 10,
          done:function(msg){
             if (msg.codes == 0) {
                layer.alert(msg.infomsg,{time:1000,icon:5});
             }
          }
      });

     /* //修改状态
      form.on('switch(status)', function(obj){
            var urls = "/admin/config/status";
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var status = obj.elem.checked===true?1:0;
            $.post(urls,{'id':id,'status':status},function(msg) {
                  layer.close(loading);
                  var msg = JSON.parse(msg);
                  if(msg.code == 1){
                      layer.msg(msg.infomsg,{time:1000,icon:6});
                      tableIn.reload();
                  }else{
                      layer.msg(msg.infomsg,{time:1000,icon:5});
                }
            });
      });*/
      
      //单条记录删除
      table.on('tool(list)', function(obj) {
            var urls = "/admin/userlist/delusers";
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除该记录吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post(urls,{user_id:data.user_id},function(msg){
                        layer.close(loading);
                        var msg = JSON.parse(msg);
                        if(msg.code == 1){
                            layer.msg(msg.infomsg,{time:1000,icon:6});
                            tableIn.reload();
                        }else{
                            layer.msg(msg.infomsg,{time:1000,icon:5});
                        }
                    });
                    layer.close(index);
                });
            }
        });

      //批量删除
      $("#delAll").click(function(){
          var urls = "/admin/userlist/delallusers";
          layer.confirm('确认要删除选中信息吗？',{icon: 3},function(index) {
            layer.close(index);
            var checkStatus = table.checkStatus('list'); //test即为参数id设定的值
            var ids = [];
            $(checkStatus.data).each(function (i, o) {
                ids.push(o.user_id);
            });

            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post(urls,{user_id:ids},function(msg){
            	// console.log(msg);return false;
                layer.close(loading);
                var msg = JSON.parse(msg);
                if (msg.code == 1) {
                    layer.msg(msg.infomsg, {time: 1000, icon: 6});
                    tableIn.reload();
                }else{
                    layer.msg(msg.infomsg, {time: 1000, icon: 5});
                }
            });
          })
      });
       
      //搜索内容
      $('#search').on('click', function() {
            var key = $('#key').val();
            if($.trim(key)==='') {
                layer.msg('请输入关键字！',{icon:0});
                return;
            }
            tableIn.reload({
                where: {key: key}
            });
      });

      //导出会员
      $('#daochu').click(function(){
          var urls = url + "/admin/userlist/exportuser";
          window.location.href= urls;
      });
});
</script>
</body>
</html>